home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FAQ.SWG / 0037_Re: RAR Archives.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  8KB  |  284 lines

  1.  
  2.  MM> Does anyone have the structures for RAR archived files?
  3.  
  4.  ██████╗   █████╗  ██████╗
  5.  ██╔══██╗ ██╔══██╗ ██╔══██╗     RAR version 1.53 - Technical information
  6.  ██████╔╝ ███████║ ██████╔╝     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7.  ██╔══██╗ ██╔══██║ ██╔══██╗
  8.  ██║  ██║ ██║  ██║ ██║  ██║
  9.  ╚═╝  ╚═╝ ╚═╝  ╚═╝ ╚═╝  ╚═╝
  10.  
  11.  ┌────────────────────────────────────────────────────────────────────────┐
  12.  │THE ARCHIVE FORMAT DESCRIBED BELOW IS ONLY VALID FOR VERSIONS SINCE 1.50│
  13.  └────────────────────────────────────────────────────────────────────────┘
  14.  
  15.  ╔════════════════════════════════════════════════════════════════════════╗
  16.  ║ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ RAR archive file format ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
  17.  ╚════════════════════════════════════════════════════════════════════════╝
  18.  
  19.    Archive file consists of variable length blocks. The order of these
  20. blocks may vary, but the first block must be marker block followed by
  21. an archive header block.
  22.  
  23.    Each block begins with following fields:
  24.  
  25. HEAD_CRC       2 bytes     CRC of total block or block part
  26. HEAD_TYPE      1 byte      Block type
  27. HEAD_FLAGS     2 bytes     Block flags
  28. HEAD_SIZE      2 bytes     Block size
  29. ADD_SIZE       4 bytes     Optional field - added block size
  30.  
  31.    Field ADD_SIZE present only if (HEAD_FLAGS & 0x8000) != 0
  32.  
  33.    Total block size is HEAD_SIZE if (HEAD_FLAGS & 0x8000) == 0
  34. and HEAD_SIZE+ADD_SIZE if the field ADD_SIZE is present - when
  35. (HEAD_FLAGS & 0x8000) != 0.
  36.  
  37.    In each block the followings bits in HEAD_FLAGS have the same meaning:
  38.  
  39.   0x4000 - if set, older RAR versions will ignore the block
  40.            and remove it when the archive is updated.
  41.            if clear, the block is copied to the new archive
  42.            file when the archive is updated;
  43.  
  44.   0x8000 - if set, ADD_SIZE field is present and the full block
  45.            size is HEAD_SIZE+ADD_SIZE.
  46.  
  47.   Declared block types:
  48.  
  49. HEAD_TYPE=0x72          marker block
  50. HEAD_TYPE=0x73          archive header
  51. HEAD_TYPE=0x74          file header
  52. HEAD_TYPE=0x75          comment header
  53. HEAD_TYPE=0x76          extra information
  54.  
  55.    Comment block is actually used only within other blocks and does not
  56. exist separately.
  57.  
  58.    Archive processing is made in the following manner:
  59.  
  60. 1. Read and check marker block
  61. 2. Read archive header
  62. 3. Read or skip HEAD_SIZE-sizeof(MAIN_HEAD) bytes
  63. 4. If end of archive encountered then terminate archive processing,
  64.    else read 7 bytes into fields HEAD_CRC, HEAD_TYPE, HEAD_FLAGS,
  65.    HEAD_SIZE.
  66. 5. Check HEAD_TYPE.
  67.    In case block read needed:
  68.          if HEAD_TYPE==0x74
  69.            read file header ( first 7 bytes already read )
  70.            read or skip HEAD_SIZE-sizeof(FILE_HEAD) bytes
  71.            read or skip FILE_SIZE bytes
  72.          else
  73.            read corresponding HEAD_TYPE block:
  74.              read HEAD_SIZE-7 bytes
  75.              if (HEAD_FLAGS & 0x8000)
  76.                read ADD_SIZE bytes
  77.    In case block skip needed:
  78.          skip HEAD_SIZE-7 bytes
  79.          if (HEAD_FLAGS & 0x8000)
  80.            skip ADD_SIZE bytes
  81. 6. go to 4.
  82.  
  83.  
  84.  ╔════════════════════════════════════════════════════════════════════════╗
  85.  ║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  Block Formats  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
  86.  ╚════════════════════════════════════════════════════════════════════════╝
  87.  
  88.  
  89.    Marker block ( MARK_HEAD )
  90.  
  91.  
  92. HEAD_CRC        Always 0x6152
  93. 2 bytes
  94.  
  95. HEAD_TYPE       Header type: 0x72
  96. 1 byte
  97.  
  98. HEAD_FLAGS      Always 0x1a21
  99. 2 bytes
  100.  
  101. HEAD_SIZE       Block size = 0x0007
  102. 2 bytes
  103.  
  104.    The marker block is actually considered as a fixed byte
  105. sequence: 0x52 0x61 0x72 0x21 0x1a 0x07 0x00
  106.  
  107.  
  108.  
  109.    Archive header ( MAIN_HEAD )
  110.  
  111.  
  112. HEAD_CRC        CRC of fields HEAD_TYPE to RESERVED2
  113. 2 bytes
  114.  
  115. HEAD_TYPE       Header type: 0x73
  116. 1 byte
  117.  
  118. HEAD_FLAGS      Bit flags:
  119. 2 bytes
  120.                 0x01    - Volume attribute (archive volume)
  121.                 0x02    - Archive comment present
  122.                 0x04    - Archive lock attribute
  123.                 0x08    - Solid attribute (solid archive)
  124.                 0x10    - Unused
  125.                 0x20    - Authenticity information present
  126.  
  127.                 other bits in HEAD_FLAGS are reserved for
  128.                 internal use
  129.  
  130. HEAD_SIZE       Archive header total size including archive
  131. 2 bytes         comments and other added fields
  132.  
  133. RESERVED1       Reserved
  134. 2 bytes
  135.  
  136. RESERVED2       Reserved
  137. 4 bytes
  138.  
  139.  
  140. Comment block   present if (HEAD_FLAGS & 0x02) != 0
  141.  
  142.  
  143. ????            Other included blocks - reserved for
  144.                 future use
  145.  
  146.  
  147.  
  148.    File header (File in archive)
  149.  
  150.  
  151. HEAD_CRC        CRC of fields from HEAD_TYPE to FILEATTR
  152. 2 bytes         and file name
  153.  
  154. HEAD_TYPE       Header type: 0x74
  155. 1 byte
  156.  
  157. HEAD_FLAGS      Bit flags:
  158. 2 bytes
  159.                 0x01 - file continued from previous volume
  160.                 0x02 - file continued in next volume
  161.                 0x04 - file encrypted with password
  162.                 0x08 - file comment present
  163.  
  164.                 (HEAD_FLAGS & 0x8000) == 1, because full
  165.                 block size is HEAD_SIZE + PACK_SIZE
  166.  
  167. HEAD_SIZE       File header full size including file name,
  168. 2 bytes         comments and other added fields
  169.  
  170. PACK_SIZE       Compressed file size
  171. 4 bytes
  172.  
  173. UNP_SIZE        Uncompressed file size
  174. 4 bytes
  175.  
  176. HOST_OS         Operating system used for archiving
  177. 1 byte          (value 0 stands for MS DOS)
  178.  
  179. FILE_CRC        File CRC
  180. 4 bytes
  181.  
  182. FTIME           Date and time in standard MS DOS format
  183. 4 bytes
  184.  
  185. UNP_VER         RAR version needed to extract file
  186. 1 byte
  187.  
  188. METHOD          Packing method
  189. 1 byte
  190.  
  191. NAME_SIZE       File name size
  192. 2 bytes
  193.  
  194. ATTR            File attributes
  195. 4 bytes
  196.  
  197. FILE_NAME       File name - string of NAME_LEN bytes size
  198.  
  199.  
  200. Comment block   present if (HEAD_FLAGS & 0x08) != 0
  201.  
  202.  
  203. ????            Other extra included blocks - reserved for
  204.                 future use
  205.  
  206.  
  207.  
  208.   Comment block
  209.  
  210.  
  211. HEAD_CRC        CRC of fields from HEAD_TYPE to COMM_CRC
  212. 2 bytes
  213.  
  214. HEAD_TYPE       Header type: 0x75
  215. 1 byte
  216.  
  217. HEAD_FLAGS      Bit flags
  218. 2 bytes
  219.  
  220. HEAD_SIZE       Comment header size + comment size
  221. 2 bytes
  222.  
  223. UNP_SIZE        Uncompressed comment size
  224. 2 bytes
  225.  
  226. UNP_VER         RAR version needed to extract comment
  227. 1 byte
  228.  
  229. METHOD          Packing method
  230. 1 byte
  231.  
  232. COMM_CRC        Comment CRC
  233. 2 bytes
  234.  
  235. COMMENT         Comment text
  236.  
  237.  
  238.  
  239.   Extra info block
  240.  
  241.  
  242. HEAD_CRC        Block CRC
  243. 2 bytes
  244.  
  245. HEAD_TYPE       Header type: 0x76
  246. 1 byte
  247.  
  248. HEAD_FLAGS      Bit flags
  249. 2 bytes
  250.  
  251. HEAD_SIZE       Total block size
  252. 2 bytes
  253.  
  254. INFO            Other data
  255.  
  256.  
  257.  ╔════════════════════════════════════════════════════════════════════════╗
  258.  ║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  Application notes  ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒║
  259.  ╚════════════════════════════════════════════════════════════════════════╝
  260.  
  261.  
  262.    1. Should fields and included blocks be added in the future, their
  263. size would be included in HEAD_SIZE.
  264.  
  265.    2. To process SFX archive you need to skip the SFX module searching
  266. marker block in the archive. There is no marker block sequence (0x52 0x61
  267. 0x72 0x21 0x1a 0x07 0x00) in the SFX module itself.
  268.  
  269.    3. The CRC is calculated using the standard polynomial 0xEDB88320. In
  270. case the size of the CRC is less than 4 bytes, only the low order bytes
  271. are used.
  272.  
  273.    4. Packing method encoding:
  274.          0x30 - storing
  275.          0x31 - fastest compression
  276.          0x32 - fast compression
  277.          0x33 - normal compression
  278.          0x34 - good compression
  279.          0x35 - best compression
  280.  
  281.    5. The RAR extraction version number is encoded as 10 * Major version
  282. + minor version.
  283.  
  284.